cordova.define("com.cmpsoft.mobile.plugin.pushnotification.FGPushNotification", function (require, exports, module) {
    var cordova = require('cordova'),
        exec = require('cordova/exec');

    var FGPushNotification = function () {
        this.registered = false;
    };
    FGPushNotification.prototype.init = function (api_key) {
        exec(fastgoPushNotification.successFn, fastgoPushNotification.failureFn, 'FGPushNotification', 'init', [api_key]);
    };

    FGPushNotification.prototype.successFn = function (info) {
        window.localStorage.info = JSON.stringify(info);
        if (info) {
            var self = {
                appId: info.appId || null,
                devicetype: info.deviceType || null,
                userId: info.userId || null,
                channalId: info.channelId || null
            };
            var url = serverURL + "cmcp/phone/doRegister";
            var href = location.href;
            var len = href.lastIndexOf("/");
            var urlHTML = href.substr(0, len - 5) + "dbrw/dbrw.html";
            PostCP(url, self, function () {
                 // Alert(info);
                // window.plugins.getIntent.hide();
                //   window.openView(urlHTML);
                //   window.closeView();
            }, function () {
                //    Alert("云推送注册失败");
                //  window.openView(urlHTML);
                //  window.closeView();
            });
            fastgoPushNotification.registered = true;
            cordova.fireDocumentEvent("cloudPushRegistered", info);
        }
        else {
            // Alert("获取设备信息失败");
        }
    };

    FGPushNotification.prototype.failureFn = function (info) {
        fastgoPushNotification.registered = false;
        //  Alert("云推送注册失败了");
    };

    var fastgoPushNotification = new FGPushNotification();

    module.exports = fastgoPushNotification;
});
